const Controller = require("egg").Controller;

class BaseController extends Controller {
  // 用来传递list表格的时候需要的返回对象
  successForList(data, pageSize, currentPage,all) {
    this.ctx.body = {
      list: data,
      pagination: {
        total: all.length,
        pageSize: parseInt(pageSize) || 10,
        current: parseInt(currentPage) || 1
      }
    };
  }

  //一般操作返回的对象
  success(data) {
    this.ctx.body = {
      data,
      success: true
    };
  }

  //失败返回的对象
  failure(msg, e){
    this.ctx.body = {
      success: false,
      msg: msg,
      error: e
    };
  }

  //没找到？？好像用不到耶
  notFound(msg) {
    msg = msg || "not found";
    this.ctx.throw(404, msg);
  }
}

module.exports = BaseController;
